﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;

namespace IWebApp2
{
    /*
    public class ChatForm : Form
    {
        public static string id = String.Empty;
        private GraphicsPath oPath;
        private bool IsFormBeingDragged = false;
        private int MouseDownX;
        private int MouseDownY;
        //public delegate void ListBoxCallback(String str);
        private System.Windows.Forms.Button button3;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.Button button4;
        public ListBox listBox1;
        public System.Windows.Forms.Label User;
        private System.ComponentModel.IContainer components = null;
        private Thread myThread;
        public delegate void ListBoxCallback(String sender, String msg);
        
        public void InitializeComponent()
        {
            //System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ChatForm));
            this.button3 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.button1 = new System.Windows.Forms.Button();
            this.listBox1 = new System.Windows.Forms.ListBox();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.button4 = new System.Windows.Forms.Button();
            this.User = new System.Windows.Forms.Label();
            //this.SuspendLayout();
            // 
            // button3
            // 
            this.button3.BackColor = System.Drawing.Color.DodgerBlue;
            this.button3.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.minimize ));
            this.button3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
            this.button3.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.button3.Location = new System.Drawing.Point(376, 8);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(18, 20);
            this.button3.TabIndex = 22;
            this.button3.UseVisualStyleBackColor = false;
            this.button3.Click += new System.EventHandler(this.button3_Click);
            // 
            // button2
            // 
            this.button2.BackColor = System.Drawing.Color.DodgerBlue;
            this.button2.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.maximize));
            this.button2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
            this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.button2.Location = new System.Drawing.Point(392, 8);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(18, 20);
            this.button2.TabIndex = 21;
            this.button2.UseVisualStyleBackColor = false;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // button1
            // 
            this.button1.BackColor = System.Drawing.Color.DodgerBlue;
            this.button1.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.close));
            this.button1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
            this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.button1.Location = new System.Drawing.Point(408, 8);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(18, 20);
            this.button1.TabIndex = 20;
            this.button1.UseVisualStyleBackColor = false;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // listBox1
            // 
            
            this.listBox1.FormattingEnabled = true;
            this.listBox1.ItemHeight = 16;
            this.listBox1.Location = new System.Drawing.Point(8, 32);
            this.listBox1.Name = "listBox1";
            this.listBox1.ScrollAlwaysVisible = true;
            this.listBox1.Size = new System.Drawing.Size(417, 180);
            this.listBox1.TabIndex = 23;
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(8, 224);
            this.textBox1.Multiline = true;
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(320, 48);
            this.textBox1.TabIndex = 24;
            // 
            // button4
            // 
            this.button4.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.button4.ForeColor = System.Drawing.SystemColors.ButtonFace;
            this.button4.Image = ((System.Drawing.Image)(Properties.Resources.btn_blue_left));
            this.button4.Location = new System.Drawing.Point(335, 225);
            this.button4.Name = "button4";
            this.button4.Size = new System.Drawing.Size(88, 48);
            this.button4.TabIndex = 25;
            this.button4.Text = "Send";
            this.button4.UseVisualStyleBackColor = true;
            this.button4.Click += new System.EventHandler(this.button4_Click);
            // 
            // User
            // 
            this.User.AutoSize = true;
            this.User.BackColor = System.Drawing.Color.LightGray;
            this.User.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.User.ForeColor = System.Drawing.Color.RoyalBlue;
            this.User.Image = ((System.Drawing.Image)(Properties.Resources.labelbox));
            this.User.Location = new System.Drawing.Point(8, 8);
            this.User.Name = "User";
            this.User.Size = new System.Drawing.Size(52, 17);
            this.User.TabIndex = 26;
            this.User.Text = String.Empty;
            // 
            // ChatForm
            // 
            
            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.SystemColors.AppWorkspace;
            this.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.textbox));
            this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            this.ClientSize = new System.Drawing.Size(439, 288);
            this.Controls.Add(this.User);
            this.Controls.Add(this.button4);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.listBox1);
            this.Controls.Add(this.button3);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.button1);
            this.DoubleBuffered = true;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.Location = new System.Drawing.Point(500, 300);
            this.Name = "ChatForm";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Chat Box";
            this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ChatForm_MouseUp);
            this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ChatForm_MouseDown);
            this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ChatForm_MouseMove);
            //this.ResumeLayout(false);
            //this.PerformLayout();

        }

        private void ReceiveMessages()
        {
            try
            {
                while (true)
                {

                    if (IWebApp2.IMForm.offmessage.Count > 0)
                    {
                        MessageBox.Show("off message count before dequeue " + IWebApp2.IMForm.offmessage.Count.ToString());
                        foreach (MessageInfo obj1 in IWebApp2.IMForm.offmessage)
                        {
                            MessageBox.Show("off message value " + obj1.from);
                            if (obj1.from == this.User.Text)
                            {
                                MessageInfo m = new MessageInfo();
                                m = IWebApp2.IMForm.offmessage.Dequeue();
                                MessageBox.Show("m values " + m.to + " " + m.from + " " + m.body);
                                listBox1.Invoke(new ListBoxCallback(Update_ListBox), new object[] { m.from, m.body });
                                MessageBox.Show("off Message count after dequeue" + IWebApp2.IMForm.offmessage.Count.ToString());
                            }
                        }
                    }
                    if (!IWebApp2.SignIn.jabberClient1.IsAuthenticated)
                    {
                        if (myThread.IsAlive)
                        {
                            myThread.Abort();
                            break;
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

        }
        //public void Call(String str)
        //{
        //    listBox1.Items.Add(str);
        //}

        public void Update_ListBox(String sender, String msg)
        {
            listBox1.Items.Add(sender + ": " + msg);

        }

        public ChatForm()
        {
           InitializeComponent();
          

            IWebApp2.IMForm.Forms.Add(this);

            oPath = new GraphicsPath();
            Point[] myArray =
             {
                 new Point(0, 9),
                 new Point(1,7),
                 new Point(2,5),
                 new Point(4,3),
                 new Point(8, 1),
                 new Point(9,1),    //upper left corner
               
                 new Point(427,0),
                 new Point(430,2),
                 new Point(432,3),
                 new Point(433,5),
                 new Point(434,7),
                 new Point(436,10),
                 new Point(437,12),  //upper right corner
              
                 new Point(437,274),
                 new Point(436,277),
                 new Point(435,280),
                 new Point(433,283),
                 new Point(430,285),
                 new Point(427,287),
                 new Point(424,288),  //lower right corner
                 
                 new Point(11,288),
                 new Point(9,287),
                 new Point(7,286),
                 new Point(4,284),
                 new Point(2,282),
                 new Point(1,280),
                 new Point(0,278),   //lower left corner

             };

            oPath.AddPolygon(myArray);
            this.Region = new Region(oPath);
            ThreadStart threadStarter = new ThreadStart(ReceiveMessages);
            myThread = new Thread(threadStarter);
            myThread.IsBackground = true;
            myThread.Start();
        }

        private void ChatForm_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                IsFormBeingDragged = true;
                MouseDownX = e.X;
                MouseDownY = e.Y;
            }
        }

      
        private void ChatForm_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                IsFormBeingDragged = false;
            }
        }

        private void ChatForm_MouseMove(object sender, MouseEventArgs e)
        {
            if (IsFormBeingDragged)
            {
                Point temp = new Point();
                temp.X = this.Location.X + (e.X - MouseDownX);
                temp.Y = this.Location.Y + (e.Y - MouseDownY);
                this.Location = temp;
                temp.X = 0;
                temp.Y = 0;

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
           
            //close
            //this.Hide();
            this.Hide();
            //this.Visible = false;
            //Hide2();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //maximize
            this.WindowState = FormWindowState.Maximized;

        }

        private void button3_Click(object sender, EventArgs e)
        {
            //minimize
            foreach (Form f in IWebApp2.IMForm.Forms)
                IWebApp2.IMForm.Forms.Remove(f);
            this.WindowState = FormWindowState.Minimized;
           
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
            IWebApp2.IMForm.Forms.Remove(this);
        }

        private void button4_Click(object sender, EventArgs e)
        {
           //MessageBox.Show(this.Name + " " + textBox1.Text);
            string jid=String.Empty;
            foreach (UserInfo str in IWebApp2.IMForm.userQ)
            {

                if (str.UserName == this.Name)
                {
                    jid = str.JID;
                    MessageBox.Show(str.UserName+ " " + jid);
                    IWebApp2.SignIn.jabberClient1.Message(jid, textBox1.Text);
                }
            }

           
        }


    }*/
}
